<template>
  <div class="profile">
    <div class="profile-header">
      <h1>个人中心</h1>
      <p>管理您的个人信息和游戏数据</p>
    </div>
    
    <div class="profile-content">
      <el-row :gutter="20">
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><User /></el-icon>
                <span>个人信息</span>
              </div>
            </template>
            <div class="user-info">
              <el-avatar :size="80" :src="userStore.user?.avatar">
                {{ userStore.user?.username?.charAt(0).toUpperCase() }}
              </el-avatar>
              <div class="user-details">
                <h3>{{ userStore.user?.username }}</h3>
                <p>{{ userStore.user?.email }}</p>
                <p>注册时间：{{ formatDate(userStore.user?.createdAt) }}</p>
              </div>
            </div>
            <el-button type="primary" @click="editProfile">编辑资料</el-button>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><UserFilled /></el-icon>
                <span>我的角色</span>
              </div>
            </template>
            <p>管理您的角色卡和角色数据</p>
            <el-button type="primary" @click="manageCharacters">管理角色</el-button>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><Document /></el-icon>
                <span>我的模组</span>
              </div>
            </template>
            <p>查看和管理您创建的模组</p>
            <el-button type="primary" @click="manageModules">管理模组</el-button>
          </el-card>
        </el-col>
      </el-row>
      
      <el-row :gutter="20" style="margin-top: 20px;">
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><Clock /></el-icon>
                <span>游戏记录</span>
              </div>
            </template>
            <p>查看您的游戏历史和统计信息</p>
            <el-button type="primary" @click="viewGameHistory">查看记录</el-button>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><Setting /></el-icon>
                <span>账户设置</span>
              </div>
            </template>
            <p>修改密码、邮箱等账户信息</p>
            <el-button type="primary" @click="accountSettings">账户设置</el-button>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="profile-card">
            <template #header>
              <div class="card-header">
                <el-icon><QuestionFilled /></el-icon>
                <span>帮助支持</span>
              </div>
            </template>
            <p>获取帮助和支持，反馈问题</p>
            <el-button type="primary" @click="openHelp">获取帮助</el-button>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { useUserStore } from '@/stores/user'
import { ElMessage } from 'element-plus'

const userStore = useUserStore()

const formatDate = (dateString) => {
  if (!dateString) return '未知'
  return new Date(dateString).toLocaleDateString('zh-CN')
}

const editProfile = () => {
  ElMessage.info('编辑资料功能开发中...')
}

const manageCharacters = () => {
  ElMessage.info('角色管理功能开发中...')
}

const manageModules = () => {
  ElMessage.info('模组管理功能开发中...')
}

const viewGameHistory = () => {
  ElMessage.info('游戏记录功能开发中...')
}

const accountSettings = () => {
  ElMessage.info('账户设置功能开发中...')
}

const openHelp = () => {
  ElMessage.info('帮助支持功能开发中...')
}
</script>

<style scoped>
.profile {
  padding: 40px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.profile-header {
  text-align: center;
  margin-bottom: 40px;
}

.profile-header h1 {
  font-size: 36px;
  margin: 0 0 16px 0;
  color: #333;
}

.profile-header p {
  font-size: 18px;
  color: #666;
  margin: 0;
}

.profile-content {
  margin-top: 40px;
}

.profile-card {
  height: 100%;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
}

.card-header .el-icon {
  font-size: 20px;
  color: #667eea;
}

.profile-card p {
  color: #666;
  line-height: 1.6;
  margin: 16px 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.user-details h3 {
  margin: 0 0 8px 0;
  color: #333;
}

.user-details p {
  margin: 4px 0;
  color: #666;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .profile {
    padding: 20px 10px;
  }
  
  .profile-header h1 {
    font-size: 28px;
  }
  
  .profile-header p {
    font-size: 16px;
  }
  
  .user-info {
    flex-direction: column;
    text-align: center;
  }
}
</style>
